#include "com/cns/android/media/MediaInfo.h"

#include <binder/Parcel.h>

using namespace android;

namespace com {
namespace cns {
namespace android {
namespace media {

MediaInfo::MediaInfo() {
}

MediaInfo::MediaInfo(const Parcel& parcel) {
    readFromParcel(&parcel);
}

MediaInfo::~MediaInfo() {
}

MediaInfo::MediaInfo(const MediaInfo& o) :
    album(o.album),
    artist(o.artist),
    title(o.title),
    albumCoverUri(o.albumCoverUri),
    radioId(o.radioId),
    radioType(o.radioType) {
}

MediaInfo& MediaInfo::operator=(const MediaInfo& o) {
    album = o.album;
    artist = o.artist;
    title = o.title;
    albumCoverUri = o.albumCoverUri;
    radioId = o.radioId;
    radioType = o.radioType;

    return *this;
}

status_t MediaInfo::writeToParcel(Parcel *parcel) const {
    status_t res;

    if (parcel == nullptr) return BAD_VALUE;

    res = parcel->writeString16(album);
    if (res != OK) return res;

    res = parcel->writeString16(artist);
    if (res != OK) return res;

    res = parcel->writeString16(title);
    if (res != OK) return res;

    res = parcel->writeString16(albumCoverUri);
    if (res != OK) return res;

    res = parcel->writeString16(radioId);
    if (res != OK) return res;

    res = parcel->writeString16(radioType);

    return res;
}

status_t MediaInfo::readFromParcel(const Parcel *parcel) {
    if (parcel == nullptr) return BAD_VALUE;

    album = readMaybeEmptyString16(parcel);
    artist = readMaybeEmptyString16(parcel);
    title = readMaybeEmptyString16(parcel);
    albumCoverUri = readMaybeEmptyString16(parcel);
    radioId = readMaybeEmptyString16(parcel);
    radioType = readMaybeEmptyString16(parcel);

    return OK;
}

void MediaInfo::setAlbum(const String16& album) {
    this->album = album;
}

void MediaInfo::setArtist(const String16& artist) {
    this->artist = artist;
}

void MediaInfo::setTitle(const String16& title) {
    this->title = title;
}

void MediaInfo::setAlbumCoverUri(const String16& albumCoverUri) {
    this->albumCoverUri = albumCoverUri;
}

void MediaInfo::setRadioId(const String16& radioId) {
    this->radioId = radioId;
}

void MediaInfo::setRadioType(const String16& radioType) {
    this->radioType = radioType;
}

const String16& MediaInfo::getAlbum() const {
    return album;
}

const String16& MediaInfo::getArtist() const {
    return artist;
}

const String16& MediaInfo::getTitle() const {
    return title;
}

const String16& MediaInfo::getAlbumCoverUri() const {
    return albumCoverUri;
}

const String16& MediaInfo::getRadioId() const {
    return radioId;
}

const String16& MediaInfo::getRadioType() const {
    return radioType;
}

String16 MediaInfo::readMaybeEmptyString16(const Parcel *parcel) {
    size_t len;
    const char16_t* str = parcel->readString16Inplace(&len);

    if (str != nullptr) {
        return String16(str, len);
    } else {
        return String16();
    }
}

}  // namespace media
}  // namespace android
}  // namespace cns
}  // namespace com
